package de.gbeine.java.ebookmanager.yaml;

import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;

/**
 *
 */
public class NodeSelector {

	private final String nodeName;

	public NodeSelector(final String pNodeName) {
		this.nodeName = pNodeName;
	}

    /**
     * Determines if a node will be selected by the name choosen.
     *
     * A node will be selected, if it is a ScalarNode and the name matches.
     *
     * @param pNode The node to check
     * @return True, if node will be selected, otherwise false
     */
    public boolean select(final Node pNode) {
        return pNode.getClass().equals(ScalarNode.class)
            && nodeName.equals(((ScalarNode) pNode).getValue());
    }
}
